package com.asset.dispoal.plaintiffConfiguration.service.commom.request;

import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.multipart.MultipartFile;
import tech.mhuang.pacebox.core.util.CollectionUtil;
import tech.mhuang.pacebox.springboot.core.entity.RequestModel;
import tech.mhuang.pacebox.springboot.core.rest.SingleRestTemplate;
import tech.mhuang.pacebox.springboot.core.spring.start.SpringContextHolder;

import java.util.List;


/**
 * @author qr
 * @date 2022/3/22$
 */
public class PlaintiffConfigurationRequest {
    public static void request(List<MultipartFile> files, String id, String fileType) {
        if (CollectionUtil.isEmpty(files)) {
            return;
        }
        RequestModel<String> requestModel = new RequestModel<String>() {
        };
        MultiValueMap<String, Object> stringObjectMap = new LinkedMultiValueMap<>(3);
        stringObjectMap.add("files", files);
        stringObjectMap.add("plaintiffId", id);
        stringObjectMap.add("fileType", fileType);
        requestModel.setParams(stringObjectMap);
        requestModel.setMethod(HttpMethod.POST);
        requestModel.setMediaType(MediaType.MULTIPART_FORM_DATA);
        requestModel.setUrl("http://127.0.0.1:9013/");
        requestModel.setSufUrl("file/plaintiffFile/insert");
        SingleRestTemplate singleRestTemplate = SpringContextHolder.getBean(SingleRestTemplate.class);
        singleRestTemplate.request(requestModel);
    }
}
